package com.restaurant.application.indexes.couponmanagelist.mysql;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.nebutown.base.Unit;
import com.nebutown.description.data.SortSpec;
import com.nebutown.generation.basictype.UID;
import com.nebutown.supporthome.AbstractIndex;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

public class CouponManageListImpl extends AbstractIndex<CouponManageListCriteria, CouponManageListBean> {

    @Override
    public String getTableName() {
        return "" + getConnectionName() + ".COUPONMANAGELIST";
    }

    @Override
    public CouponManageListBean newBean() {
        return new CouponManageListBean();
    }

    @Override
    public CouponManageListCriteria newCriteria() {
        return new CouponManageListCriteria();
    }

    @Override
    public List<String> getFieldNames() {
        return Lists.newArrayList(
                "couponManageUid",
                "id",
                "number",
                "createTime",
                "modifyTime",
                "receiveTime",
                "endTime",
                "type",
                "modality",
                "fullMoney",
                "minusMoney",
                "shopUid",
                "shopName",
                "remarks",
                "totalAmount",
                "amount",
                "state",
                "limitId",
                "limitAccount");
    }

    @Override
    public List<String> getDateFields() {
        return Lists.newArrayList(
                "createTime",
                "modifyTime",
                "receiveTime",
                "endTime");
    }

    @Override
    public List<String> getDoubleFields() {
        return Lists.newArrayList(
                "fullMoney",
                "minusMoney");
    }

    @Override
    public Map<String, String> getFieldLabels() {
        return ImmutableMap.<String, String>builder()
                .put("id", "优惠券管理id")
                .put("number", "优惠券管理id")
                .put("createTime", "创建时间")
                .put("modifyTime", "修改时间")
                .put("receiveTime", "服务开始时间")
                .put("endTime", "服务期限时间")
                .put("type", "优惠券类型")
                .put("modality", "优惠券形式")
                .put("fullMoney", "满多少金额")
                .put("minusMoney", "减多少金额")
                .put("shopUid", "店铺Uid")
                .put("shopName", "店铺名称")
                .put("remarks", "备注（注意事项）")
                .put("totalAmount", "总数")
                .put("amount", "已有数")
                .put("state", "状态")
                .put("limitId", "状态")
                .put("limitAccount", "状态")
                .build();
    }

    @Override
    public List<String> getContributors() {
        return Lists.newArrayList(
                "com.restaurant.application.indexes.couponmanagelist.CouponManagePre");
    }

    @Override
    public CouponManageListBean fakeBean() {
        CouponManageListBean bean = new CouponManageListBean();

        bean.setCouponManageUid(UID.recover("A -8445687518359651318 looooong string"));
        bean.setId("A 325107332357554712 looooong string");
        bean.setNumber("A -2091278515912619467 looooong string");
        bean.setCreateTime(325948507L);
        bean.setModifyTime(1995679499L);
        bean.setReceiveTime(1529519611L);
        bean.setEndTime(-1776029552L);
        bean.setType("A 6341061256466784627 looooong string");
        bean.setModality("A 2266614405090309339 looooong string");
        bean.setFullMoney(0.8751288823004725);
        bean.setMinusMoney(0.5242889664994819);
        bean.setShopUid("A 772201793659027331 looooong string");
        bean.setShopName("A 1693712716594366138 looooong string");
        bean.setRemarks("A -5091125785999730596 looooong string");
        bean.setTotalAmount("A -3517158953674148395 looooong string");
        bean.setAmount("A -3833961434370548221 looooong string");
        bean.setState("A -7896408723151700950 looooong string");
        bean.setLimitId("A 13024220874366635 looooong string");
        bean.setLimitAccount("A -1594734464507516791 looooong string");
        return bean;
    }

    @Override
    public String getCreateTableStatement() {
        StringBuilder buf = new StringBuilder();

        buf.append("CREATE TABLE IF NOT EXISTS " + getConnectionName() + ".COUPONMANAGELIST (\n");
        buf.append("    RECORD_ID BIGINT AUTO_INCREMENT,\n");
        buf.append("    COUPONMANAGEUID CHAR(128) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,\n");
        buf.append("    ID VARCHAR(255),\n");
        buf.append("    NUMBER VARCHAR(255),\n");
        buf.append("    CREATETIME BIGINT,\n");
        buf.append("    MODIFYTIME BIGINT,\n");
        buf.append("    RECEIVETIME BIGINT,\n");
        buf.append("    ENDTIME BIGINT,\n");
        buf.append("    TYPE VARCHAR(255),\n");
        buf.append("    MODALITY VARCHAR(255),\n");
        buf.append("    FULLMONEY REAL,\n");
        buf.append("    MINUSMONEY REAL,\n");
        buf.append("    SHOPUID VARCHAR(255),\n");
        buf.append("    SHOPNAME VARCHAR(255),\n");
        buf.append("    REMARKS VARCHAR(255),\n");
        buf.append("    TOTALAMOUNT VARCHAR(255),\n");
        buf.append("    AMOUNT VARCHAR(255),\n");
        buf.append("    STATE VARCHAR(255),\n");
        buf.append("    LIMITID VARCHAR(255),\n");
        buf.append("    LIMITACCOUNT VARCHAR(255),\n");
        buf.append("PRIMARY KEY (RECORD_ID)) CHARACTER SET  = utf8mb4 COLLATE = utf8mb4_bin");
        return buf.toString();
    }

    @Override
    public String getInsertDataStatement(CouponManageListBean data) {
        StringBuilder buf = new StringBuilder();

        buf.append("INSERT INTO " + getConnectionName() + ".COUPONMANAGELIST (\n    ");
        buf.append("    COUPONMANAGEUID, ID, NUMBER, CREATETIME, MODIFYTIME, RECEIVETIME, ENDTIME, TYPE, MODALITY, FULLMONEY, MINUSMONEY, SHOPUID, SHOPNAME, REMARKS, TOTALAMOUNT, AMOUNT, STATE, LIMITID, LIMITACCOUNT");
        buf.append(") VALUES (");
        buf.append("    '" + cut(data.getCouponManageUid(), 128) + "', '" + cut(data.getId(), 255) + "', '" + cut(data.getNumber(), 255) + "', " + data.getCreateTime() + ", " + data.getModifyTime() + ", " + data.getReceiveTime() + ", " + data.getEndTime() + ", '" + cut(data.getType(), 255) + "', '" + cut(data.getModality(), 255) + "', " + data.getFullMoney() + ", " + data.getMinusMoney() + ", '" + cut(data.getShopUid(), 255) + "', '" + cut(data.getShopName(), 255) + "', '" + cut(data.getRemarks(), 255) + "', '" + cut(data.getTotalAmount(), 255) + "', '" + cut(data.getAmount(), 255) + "', '" + cut(data.getState(), 255) + "', '" + cut(data.getLimitId(), 255) + "', '" + cut(data.getLimitAccount(), 255) + "'");
        buf.append(")");
        return buf.toString();
    }

    @Override
    public String getDeleteRowsStatement(Long rowId) {
        return "DELETE FROM " + getConnectionName() + ".COUPONMANAGELIST WHERE  RECORD_ID = " + rowId;
    }

    @Override
    public String getLocalUpdateStatement(CouponManageListBean data) {
        StringBuilder buf = new StringBuilder();
        StringBuilder sep = new StringBuilder();

        boolean hasData = false;

        buf.append("UPDATE " + getConnectionName() + ".COUPONMANAGELIST \n");
        buf.append("   SET ");
        if(data.getCouponManageUid() != null) {
            buf.append(sep.toString() + "\n      COUPONMANAGEUID = '" + cut(data.getCouponManageUid(), 128) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getId() != null) {
            buf.append(sep.toString() + "\n      ID = '" + cut(data.getId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getNumber() != null) {
            buf.append(sep.toString() + "\n      NUMBER = '" + cut(data.getNumber(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCreateTime() != null) {
            buf.append(sep.toString() + "\n      CREATETIME = " + data.getCreateTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModifyTime() != null) {
            buf.append(sep.toString() + "\n      MODIFYTIME = " + data.getModifyTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getReceiveTime() != null) {
            buf.append(sep.toString() + "\n      RECEIVETIME = " + data.getReceiveTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getEndTime() != null) {
            buf.append(sep.toString() + "\n      ENDTIME = " + data.getEndTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getType() != null) {
            buf.append(sep.toString() + "\n      TYPE = '" + cut(data.getType(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModality() != null) {
            buf.append(sep.toString() + "\n      MODALITY = '" + cut(data.getModality(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getFullMoney() != null) {
            buf.append(sep.toString() + "\n      FULLMONEY = " + data.getFullMoney() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getMinusMoney() != null) {
            buf.append(sep.toString() + "\n      MINUSMONEY = " + data.getMinusMoney() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopUid() != null) {
            buf.append(sep.toString() + "\n      SHOPUID = '" + cut(data.getShopUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopName() != null) {
            buf.append(sep.toString() + "\n      SHOPNAME = '" + cut(data.getShopName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getRemarks() != null) {
            buf.append(sep.toString() + "\n      REMARKS = '" + cut(data.getRemarks(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getTotalAmount() != null) {
            buf.append(sep.toString() + "\n      TOTALAMOUNT = '" + cut(data.getTotalAmount(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getAmount() != null) {
            buf.append(sep.toString() + "\n      AMOUNT = '" + cut(data.getAmount(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getState() != null) {
            buf.append(sep.toString() + "\n      STATE = '" + cut(data.getState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getLimitId() != null) {
            buf.append(sep.toString() + "\n      LIMITID = '" + cut(data.getLimitId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getLimitAccount() != null) {
            buf.append(sep.toString() + "\n      LIMITACCOUNT = '" + cut(data.getLimitAccount(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(!hasData) return "";

        hasData = false;
        buf.append(" WHERE TRUE\n");
        if(data.getCouponManageUid() != null) {
            buf.append("    AND COUPONMANAGEUID = '" + data.getCouponManageUid() + "'\n");
            hasData = true;
        }
        if(!hasData) return "";

        return buf.toString();
    }

    @Override
    public String getUpdateByIdStatement(CouponManageListBean data) {
        StringBuilder buf = new StringBuilder();
        StringBuilder sep = new StringBuilder();

        boolean hasData = false;

        buf.append("UPDATE " + getConnectionName() + ".COUPONMANAGELIST \n");
        buf.append("   SET ");
        if(data.getCouponManageUid() != null) {
            buf.append(sep.toString() + "\n      COUPONMANAGEUID = '" + cut(data.getCouponManageUid(), 128) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getId() != null) {
            buf.append(sep.toString() + "\n      ID = '" + cut(data.getId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getNumber() != null) {
            buf.append(sep.toString() + "\n      NUMBER = '" + cut(data.getNumber(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCreateTime() != null) {
            buf.append(sep.toString() + "\n      CREATETIME = " + data.getCreateTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModifyTime() != null) {
            buf.append(sep.toString() + "\n      MODIFYTIME = " + data.getModifyTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getReceiveTime() != null) {
            buf.append(sep.toString() + "\n      RECEIVETIME = " + data.getReceiveTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getEndTime() != null) {
            buf.append(sep.toString() + "\n      ENDTIME = " + data.getEndTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getType() != null) {
            buf.append(sep.toString() + "\n      TYPE = '" + cut(data.getType(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModality() != null) {
            buf.append(sep.toString() + "\n      MODALITY = '" + cut(data.getModality(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getFullMoney() != null) {
            buf.append(sep.toString() + "\n      FULLMONEY = " + data.getFullMoney() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getMinusMoney() != null) {
            buf.append(sep.toString() + "\n      MINUSMONEY = " + data.getMinusMoney() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopUid() != null) {
            buf.append(sep.toString() + "\n      SHOPUID = '" + cut(data.getShopUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopName() != null) {
            buf.append(sep.toString() + "\n      SHOPNAME = '" + cut(data.getShopName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getRemarks() != null) {
            buf.append(sep.toString() + "\n      REMARKS = '" + cut(data.getRemarks(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getTotalAmount() != null) {
            buf.append(sep.toString() + "\n      TOTALAMOUNT = '" + cut(data.getTotalAmount(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getAmount() != null) {
            buf.append(sep.toString() + "\n      AMOUNT = '" + cut(data.getAmount(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getState() != null) {
            buf.append(sep.toString() + "\n      STATE = '" + cut(data.getState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getLimitId() != null) {
            buf.append(sep.toString() + "\n      LIMITID = '" + cut(data.getLimitId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getLimitAccount() != null) {
            buf.append(sep.toString() + "\n      LIMITACCOUNT = '" + cut(data.getLimitAccount(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(!hasData) return "";

        hasData = false;
        buf.append(" WHERE RECORD_ID = " + data.getRecordId());
        return buf.toString();
    }

    @Override
    public CouponManageListBean extractLine(ResultSet resultSet) throws Exception {
        CouponManageListBean result = new CouponManageListBean();

        result.setRecordId(resultSet.getLong("RECORD_ID"));
        result.setCouponManageUid(UID.recover(resultSet.getString("couponManageUid")));
        result.setId(resultSet.getString("id"));
        result.setNumber(resultSet.getString("number"));
        result.setCreateTime(resultSet.getLong("createTime"));
        result.setModifyTime(resultSet.getLong("modifyTime"));
        result.setReceiveTime(resultSet.getLong("receiveTime"));
        result.setEndTime(resultSet.getLong("endTime"));
        result.setType(resultSet.getString("type"));
        result.setModality(resultSet.getString("modality"));
        result.setFullMoney(resultSet.getDouble("fullMoney"));
        result.setMinusMoney(resultSet.getDouble("minusMoney"));
        result.setShopUid(resultSet.getString("shopUid"));
        result.setShopName(resultSet.getString("shopName"));
        result.setRemarks(resultSet.getString("remarks"));
        result.setTotalAmount(resultSet.getString("totalAmount"));
        result.setAmount(resultSet.getString("amount"));
        result.setState(resultSet.getString("state"));
        result.setLimitId(resultSet.getString("limitId"));
        result.setLimitAccount(resultSet.getString("limitAccount"));
        return result;
    }

    @Override
    public String getWherePart(CouponManageListCriteria criteria, SortSpec sort) {
        StringBuilder buf = new StringBuilder(" TRUE ");

        criteria.setIdLike(searchString(criteria.getIdLike()));
        criteria.setNumberLike(searchString(criteria.getNumberLike()));
        criteria.setTypeLike(searchString(criteria.getTypeLike()));
        criteria.setModalityLike(searchString(criteria.getModalityLike()));
        criteria.setShopUidLike(searchString(criteria.getShopUidLike()));
        criteria.setShopNameLike(searchString(criteria.getShopNameLike()));
        criteria.setRemarksLike(searchString(criteria.getRemarksLike()));
        criteria.setTotalAmountLike(searchString(criteria.getTotalAmountLike()));
        criteria.setAmountLike(searchString(criteria.getAmountLike()));
        criteria.setStateLike(searchString(criteria.getStateLike()));
        criteria.setLimitIdLike(searchString(criteria.getLimitIdLike()));
        criteria.setLimitAccountLike(searchString(criteria.getLimitAccountLike()));

        if(criteria.getRecordId() != null) {
            buf.append("    AND RECORD_ID = " + criteria.getRecordId());
        }
        if(criteria.getCouponManageUidEquals() != null) {
            buf.append("    AND COUPONMANAGEUID = '" + criteria.getCouponManageUidEquals() + "'");
        }
        if(criteria.getCouponManageUidNotEquals() != null) {
            buf.append("    AND COUPONMANAGEUID != '" + criteria.getCouponManageUidNotEquals() + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdEquals())) {
            buf.append("    AND ID = '" + cut(criteria.getIdEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdNotEquals())) {
            buf.append("    AND ID != '" + cut(criteria.getIdNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdLike())) {
            buf.append("    AND ID LIKE '" + cut(criteria.getIdLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getNumberEquals())) {
            buf.append("    AND NUMBER = '" + cut(criteria.getNumberEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getNumberNotEquals())) {
            buf.append("    AND NUMBER != '" + cut(criteria.getNumberNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getNumberLike())) {
            buf.append("    AND NUMBER LIKE '" + cut(criteria.getNumberLike()) + "'");
        }
        if(criteria.getCreateTimeUpper() != null) {
            buf.append("    AND CREATETIME <= " + criteria.getCreateTimeUpper());
        }
        if(criteria.getCreateTimeLower() != null) {
            buf.append("    AND CREATETIME >= " + criteria.getCreateTimeLower());
        }
        if(criteria.getCreateTimeEquals() != null) {
            buf.append("    AND CREATETIME = '" + criteria.getCreateTimeEquals() + "'");
        }
        if(criteria.getCreateTimeNotEquals() != null) {
            buf.append("    AND CREATETIME != '" + criteria.getCreateTimeNotEquals() + "'");
        }
        if(criteria.getModifyTimeUpper() != null) {
            buf.append("    AND MODIFYTIME <= " + criteria.getModifyTimeUpper());
        }
        if(criteria.getModifyTimeLower() != null) {
            buf.append("    AND MODIFYTIME >= " + criteria.getModifyTimeLower());
        }
        if(criteria.getModifyTimeEquals() != null) {
            buf.append("    AND MODIFYTIME = '" + criteria.getModifyTimeEquals() + "'");
        }
        if(criteria.getModifyTimeNotEquals() != null) {
            buf.append("    AND MODIFYTIME != '" + criteria.getModifyTimeNotEquals() + "'");
        }
        if(criteria.getReceiveTimeUpper() != null) {
            buf.append("    AND RECEIVETIME <= " + criteria.getReceiveTimeUpper());
        }
        if(criteria.getReceiveTimeLower() != null) {
            buf.append("    AND RECEIVETIME >= " + criteria.getReceiveTimeLower());
        }
        if(criteria.getReceiveTimeEquals() != null) {
            buf.append("    AND RECEIVETIME = '" + criteria.getReceiveTimeEquals() + "'");
        }
        if(criteria.getReceiveTimeNotEquals() != null) {
            buf.append("    AND RECEIVETIME != '" + criteria.getReceiveTimeNotEquals() + "'");
        }
        if(criteria.getEndTimeUpper() != null) {
            buf.append("    AND ENDTIME <= " + criteria.getEndTimeUpper());
        }
        if(criteria.getEndTimeLower() != null) {
            buf.append("    AND ENDTIME >= " + criteria.getEndTimeLower());
        }
        if(criteria.getEndTimeEquals() != null) {
            buf.append("    AND ENDTIME = '" + criteria.getEndTimeEquals() + "'");
        }
        if(criteria.getEndTimeNotEquals() != null) {
            buf.append("    AND ENDTIME != '" + criteria.getEndTimeNotEquals() + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTypeEquals())) {
            buf.append("    AND TYPE = '" + cut(criteria.getTypeEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTypeNotEquals())) {
            buf.append("    AND TYPE != '" + cut(criteria.getTypeNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTypeLike())) {
            buf.append("    AND TYPE LIKE '" + cut(criteria.getTypeLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getModalityEquals())) {
            buf.append("    AND MODALITY = '" + cut(criteria.getModalityEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getModalityNotEquals())) {
            buf.append("    AND MODALITY != '" + cut(criteria.getModalityNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getModalityLike())) {
            buf.append("    AND MODALITY LIKE '" + cut(criteria.getModalityLike()) + "'");
        }
        if(criteria.getFullMoneyUpper() != null) {
            buf.append("    AND FULLMONEY <= " + criteria.getFullMoneyUpper());
        }
        if(criteria.getFullMoneyLower() != null) {
            buf.append("    AND FULLMONEY >= " + criteria.getFullMoneyLower());
        }
        if(criteria.getMinusMoneyUpper() != null) {
            buf.append("    AND MINUSMONEY <= " + criteria.getMinusMoneyUpper());
        }
        if(criteria.getMinusMoneyLower() != null) {
            buf.append("    AND MINUSMONEY >= " + criteria.getMinusMoneyLower());
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidEquals())) {
            buf.append("    AND SHOPUID = '" + cut(criteria.getShopUidEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidNotEquals())) {
            buf.append("    AND SHOPUID != '" + cut(criteria.getShopUidNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidLike())) {
            buf.append("    AND SHOPUID LIKE '" + cut(criteria.getShopUidLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameEquals())) {
            buf.append("    AND SHOPNAME = '" + cut(criteria.getShopNameEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameNotEquals())) {
            buf.append("    AND SHOPNAME != '" + cut(criteria.getShopNameNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameLike())) {
            buf.append("    AND SHOPNAME LIKE '" + cut(criteria.getShopNameLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksEquals())) {
            buf.append("    AND REMARKS = '" + cut(criteria.getRemarksEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksNotEquals())) {
            buf.append("    AND REMARKS != '" + cut(criteria.getRemarksNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksLike())) {
            buf.append("    AND REMARKS LIKE '" + cut(criteria.getRemarksLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTotalAmountEquals())) {
            buf.append("    AND TOTALAMOUNT = '" + cut(criteria.getTotalAmountEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTotalAmountNotEquals())) {
            buf.append("    AND TOTALAMOUNT != '" + cut(criteria.getTotalAmountNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTotalAmountLike())) {
            buf.append("    AND TOTALAMOUNT LIKE '" + cut(criteria.getTotalAmountLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAmountEquals())) {
            buf.append("    AND AMOUNT = '" + cut(criteria.getAmountEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAmountNotEquals())) {
            buf.append("    AND AMOUNT != '" + cut(criteria.getAmountNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAmountLike())) {
            buf.append("    AND AMOUNT LIKE '" + cut(criteria.getAmountLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateEquals())) {
            buf.append("    AND STATE = '" + cut(criteria.getStateEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateNotEquals())) {
            buf.append("    AND STATE != '" + cut(criteria.getStateNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateLike())) {
            buf.append("    AND STATE LIKE '" + cut(criteria.getStateLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLimitIdEquals())) {
            buf.append("    AND LIMITID = '" + cut(criteria.getLimitIdEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLimitIdNotEquals())) {
            buf.append("    AND LIMITID != '" + cut(criteria.getLimitIdNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLimitIdLike())) {
            buf.append("    AND LIMITID LIKE '" + cut(criteria.getLimitIdLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLimitAccountEquals())) {
            buf.append("    AND LIMITACCOUNT = '" + cut(criteria.getLimitAccountEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLimitAccountNotEquals())) {
            buf.append("    AND LIMITACCOUNT != '" + cut(criteria.getLimitAccountNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLimitAccountLike())) {
            buf.append("    AND LIMITACCOUNT LIKE '" + cut(criteria.getLimitAccountLike()) + "'");
        }
        if(sort != null && sort.getColumns().size() > 0) {
            buf.append(" ORDER BY ");
            sort.getColumns().forEach(c->buf.append(c.getColumnName().toUpperCase())
                .append(" ").append((c.getAscending() != null && c.getAscending()) ? "ASC" : "DESC")
                .append(", "));
            buf.append("RECORD_ID ASC");
        }
        return buf.toString();
    }

    @Override
    public <T extends Unit > String getUpdateStatement(T source) {
        CouponManageListBean data = null;

        if(source instanceof com.restaurant.application.indexes.couponmanagelist.mysql.CouponManageListFromcouponManageUidIF) {
            data = new CouponManageListBean();
             ((com.restaurant.application.indexes.couponmanagelist.mysql.CouponManageListFromcouponManageUidIF)source).getCouponManageUidDataForCouponManageList(data);
        }

        return data == null ? null: getLocalUpdateStatement(data);
    }
}
